package com.yixing.tech.common.convert;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Optional;

public class DateToStringConverter implements Converter<Date, String> {

    @Override
    public String convert(Date source) {
        return Optional.ofNullable(source).map(x -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(x)).orElse(null);
    }

    @Override
    public Class<Date> getSourceType() {
        return Date.class;
    }

    @Override
    public Class<String> getTargetType() {
        return String.class;
    }

}
